package cn.yunhe;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class EnocodingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("UTF-8");
        servletResponse.setCharacterEncoding("UTF-8");
        servletResponse.setContentType("text/html;charset=UTF-8");

        HttpServletResponse response = (HttpServletResponse) servletResponse;

        /*response.setHeader("Pragma","No-cache");
        response.setHeader("Cache-Control","no-cache");
        response.setDateHeader("Expires", 0);
*/

        /*// 将过期日期设置为一个过去时间

        response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");

// 设置 HTTP/1.1 no-cache 头
        response.setHeader("Cache-Control", "no-store,no-cache,must-revalidate");

// 设置 IE 扩展 HTTP/1.1 no-cache headers， 用户自己添加
        response.addHeader("Cache-Control", "post-check=0, pre-check=0");

// 设置标准 HTTP/1.0 no-cache header.
        response.setHeader("Pragma", "no-cache");*/



        filterChain.doFilter(servletRequest, servletResponse);


    }

    @Override
    public void destroy() {

    }
}
